package cn.lucky.thread.method;

/**
 * @Author: jianglingpeng
 * @Date: 2020/9/16
 * @Description:
 * sleep(1000) 让当前线程休眠1000毫秒.sleep(1000,500) 让当前线程休眠1000毫秒+500纳秒
 *  sleep方法只能使当前线程休眠,即使在当前线程中调用其他线程的sleep方法也是休眠当前线程
 *
 *
 *  JDK1.5开始 提供了一套多线程的工具JUC,下面让线程休眠的方法可读性更高
 *      TimeUnit.SECONDS.sleep(1);
 *      TimeUnit.MINUTES.sleep(1);
 *      TimeUnit.HOURS.sleep(1);
 *      TimeUnit.DAYS.sleep(1);
 *
 */
public class SleepMethod {

    public static void main(String[] args) {
        SleepThread  t = new SleepThread();
        t.start();
        try {
            t.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        for (int i = 0; i < 5; i++) {
            System.out.println(Thread.currentThread().getName() + ":" + i);
        }
    }
}

class SleepThread extends Thread{
    @Override
    public void run() {
        for (int i = 0; i < 5; i++) {
            System.out.println(Thread.currentThread().getName() + ":" + i);
        }
    }
}